package com.rss.inbound.mappers;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.rss.inbound.beans.RssEntry;
import com.rss.inbound.beans.RssSrc;
import com.rss.inbound.beans.Sts;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;

public class CultOfMacMapper implements RssMapper {
    Logger log = Logger.getLogger(CultOfMacMapper.class);

    @SuppressWarnings("unchecked")
    @Override
    public RssEntry mapRssEntry(SyndEntry entry, RssSrc rssSrc)
    {

	log.info("Processing RSS Source ==> " + rssSrc.getRssSrcTtl());

	Sts activeRssEntrySts = new Sts();
	activeRssEntrySts.setIdSts(3);

	RssEntry rssEntry = new RssEntry();
	rssEntry.setRssSrc(rssSrc);
	rssEntry.setAthr(entry.getAuthor());
	rssEntry.setTtl(entry.getTitle());
	rssEntry.setEntryLnk(entry.getUri());
	rssEntry.setDesc(entry.getDescription().getValue().getBytes());

	List<SyndContent> syndContentList = entry.getContents();
	SyndContent syndContent = syndContentList.get(0);
	rssEntry.setCntn(syndContent.getValue().getBytes());
	rssEntry.setCntnFrmt(entry.getDescription().getType());

	rssEntry.setPubDttm(entry.getPublishedDate());
	rssEntry.setSts(activeRssEntrySts);
	rssEntry.setEntryStsDttm(new Date());
	rssEntry.setCreatBy("RssDownloaderBatch");
	rssEntry.setCreatDttm(new Date());
	rssEntry.setLastModBy("RssDownloaderBatch");
	rssEntry.setLastModDttm(new Date());

	return rssEntry;
    }
}